package com.shen;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Author:shen
 * CreateDate:2020/5/24.
 * Function:
 */
public class demo02 {
    static Scanner scanner=new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println("请输入文件名：");
        String str = scanner.nextLine();
       if(check(str)==-1){
           System.out.println("提交的文件格式不正确！");
       }else{
           if(checkName(str)){
               System.out.println("提交成功");
           }else{
               System.out.println("提交文件名必须有中文名！");
           }
       }

    }
    public static int check(String str){
        int i;
        if(str.indexOf(".")>0){
            String sub = str.substring(str.lastIndexOf(".")+1,str.length());
            i=("zip".equals(sub)||"rar".equals(sub))? 1:-1;
        }else{
            i=-1;//提交的格式不正确
        }
        return i;
    }
    public static boolean checkName(String str){
        Pattern pattern=Pattern.compile("[\u4e00-\u9fa5]");//正则匹配汉字
        Matcher matcher = pattern.matcher(str);
        if(matcher.find()){//判断是否有汉字
            return true;
        }else{
            return false;
        }

    }
}
